package pa1.sockets;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;

public class Logger {
	
	private String eventFile = "events.txt";
	
	public Logger(){
		
	}
	
	//this function writes all incoming events to the logfile
	public synchronized void logEvent(int eventNumber, String clientName, String eventDescription){
		//concatenate the event string
		String event = "[" + new Date().toString() + "]" + eventNumber + ":" + clientName + ":" + eventDescription + "\n";
		//open a bufferedwriter and write the event to the log file
		try {
			BufferedWriter logWriter = new BufferedWriter(new FileWriter(eventFile , true));
			logWriter.write(event);
			logWriter.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
